        var balanceStore = new Ext.data.JsonStore({
			url: '/weihe/get_balanceList',
			root: 'datas',
			fields : [{
						name:'BalanceId',mapping:'id'
					},{
						name:'BalanceClient',mapping:'client'
					},{
						name:'BalancePayment',mapping:'payment'
					},{
						name:'BalanceDate',mapping:'date',type : 'date', dateFormat:"Y-m-d"
				    },{
				    	name:'BalanceContact',mapping:'contact'
				    },{
				    	name:'BalanceDbv',mapping:'dbv'
				    },{
				    	name:'BalanceRbv',mapping:'rbv'
				    },{
				    	name:'BalanceDcustoms',mapping:'dcustoms'
				    },{
				    	name:'BalanceRcustoms',mapping:'rcustoms'
				    },{
				    	name:'BalanceDport',mapping:'dport'
				    },{
				    	name:'BalanceRport',mapping:'rport'
				    },{
				    	name:'BalanceDsvc',mapping:'dsvc'
				    },{
				    	name:'BalanceRsvc',mapping:'rsvc'
				    },{
				    	name:'BalanceDcard',mapping:'dcard'
				    },{
				    	name:'BalanceRcard',mapping:'rcard'
				    },{
				    	name:'BalanceDcnca',mapping:'dcnca'
				    },{
				    	name:'BalanceRcnca',mapping:'rcnca'
				    },{
				    	name:'BalanceDocean',mapping:'docean'
				    },{
				    	name:'BalanceRocean',mapping:'rocean'
				    },{
				    	name:'BalanceDsum',mapping:'dsum'
				    },{
				    	name:'BalanceRsum',mapping:'rsum'
				    },{
				    	name:'BalanceBvRemark',mapping:'bvRemark'
				    },{
				    	name:'BalanceCustomRemark',mapping:'customRemark'
				    },{
				    	name:'BalancePortRemark',mapping:'portRemark'
				    },{
				    	name:'BalanceSvcRemark',mapping:'svcRemark'
				    },{
				    	name:'BalanceCncaRemark',mapping:'cncaRemark'
				    },{
				    	name:'BalanceCardRemark',mapping:'cardRemark'
				    },{
				    	name:'BalanceOceanRemark',mapping:'oceanRemark'
				    },{
				    	name:'BalanceSumRemark',mapping:'sumRemark'
				    }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_balanceList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
    	
    	

balance = function(){
	var tmp;
  return{
     
	  balanceGrid : function(){

		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 15,
			store : balanceStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
	   var balanceGrid = new Ext.grid.GridPanel({
		   id:'balanceGrid',
		   title : '库存信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   tbar:[{
			  	text:"打印结算清单",
				handler:function(){
							if(tmp!=''){
			   				window.open('/weihe/printBalanceList?balanceList.id='+ tmp, '_blank');
			   				tmp = '';
							}else{
								Ext.Msg.alert('提示','请选择要打印的数据!');
							}
				}
						
		   		},"-"],
		   store : balanceStore,
		   columns: [
		             {header : '客户', dataIndex : 'BalanceClient', menuDisabled : true},
		             {header : '装运时间', dataIndex : 'BalanceDate', menuDisabled : true,sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : '结算方式', dataIndex : 'BalancePayment'},
		             {header : '客户联系方式', dataIndex : 'BalanceContact', menuDisabled : true},
		             {header : 'bv费（美）', dataIndex : 'BalanceDbv', menuDisabled : true},
		             {header : 'bv费（中）', dataIndex : 'BalanceRbv', menuDisabled : true},
		             {header : 'bv备注', dataIndex : 'BalanceBvRemark', menuDisabled : true},
		             {header : '报关费（美）', dataIndex : 'BalanceDcustoms', menuDisabled : true},
		             {header : '报关费（中）', dataIndex : 'BalanceRcustoms', menuDisabled : true},
		             {header : '报关费备注', dataIndex : 'BalanceCustomRemark', menuDisabled : true},
		             {header : '码头费（美）', dataIndex : 'BalanceDport', menuDisabled : true},
		             {header : '码头费（中）', dataIndex : 'BalanceRport', menuDisabled : true},
		             {header : '码头费备注', dataIndex : 'BalancePortRemark', menuDisabled : true},
		             {header : '服务费（美）', dataIndex : 'BalanceDsvc', menuDisabled : true},
		             {header : '服务费（中）', dataIndex : 'BalanceRsvc', menuDisabled : true},
		             {header : '服务费备注', dataIndex : 'BalanceSvcRemark', menuDisabled : true},
		             {header : '单证费（美）', dataIndex : 'BalanceDcard', menuDisabled : true},
		             {header : '单证费（中）', dataIndex : 'BalanceRcard', menuDisabled : true},
		             {header : '单证备注', dataIndex : 'BalanceCardRemark', menuDisabled : true},
		             {header : 'CNCA（美）', dataIndex : 'BalanceDcnca', menuDisabled : true},
		             {header : 'CNCA（中）', dataIndex : 'BalanceRcnca', menuDisabled : true},
		             {header : 'CNCA备注', dataIndex : 'BalanceCncaRemark', menuDisabled : true},
		             {header : '海运费（美）', dataIndex : 'BalanceDocean', menuDisabled : true},
		             {header : '海运费（中）', dataIndex : 'BalanceRocean', menuDisabled : true},
		             {header : '海运费备注', dataIndex : 'BalanceOceanRemark', menuDisabled : true},
		             {header : '合计（美）', dataIndex : 'BalanceDsum', menuDisabled : true},
		             {header : '合计（中）', dataIndex : 'BalanceRsum', menuDisabled : true},
		             {header : '合计备注', dataIndex : 'BalanceSumRemark', menuDisabled : true}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("balanceForm").form.loadRecord(record);
			   tmp = record.get('BalanceId');
			   Ext.getCmp("balanceForm").buttons[0].setText('修改');
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return balanceGrid;
	},
	balanceForm : function(){

		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
					progressConsole();
				if(balanceForm.form.isValid()){ 	
					if (balanceForm.form.findField("balanceList.id").getValue() == "") {
						balanceForm.form.submit({
						  url : '/weihe/add_balanceList',
						   success : function(form, action) {
							  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							  }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									balanceForm.form.reset();
									   Ext.getCmp("balanceGrid").getStore().reload();
									
								});
							  }
						    }
					    });
					}else {
						balanceForm.form.submit({
							  url : '/weihe/update_balanceList',
							   success : function(form, action) {
								  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										balanceForm.form.reset();
										Ext.getCmp("balanceGrid").getStore().reload();
										balanceForm.buttons[0].setText('添加');
										
									});
								  }
							    }
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		id : 'button_clear',
		text : '清空',
		handler : function() {
			balanceForm.form.reset();
			balanceForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = balanceForm.form.findField('balanceList.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_balanceList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
						  if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									balanceForm.form.reset();
								balanceForm.buttons[0].setText('添加');
						  }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("balanceGrid").getStore().load({params : {start : 0, limit : 15}});
								balanceForm.form.reset();
								balanceForm.buttons[0].setText('添加');
							});
						   }
						}else{
							Ext.Msg.alert('消息', json.msg);
							balanceForm.form.reset();
							balanceForm.buttons[0].setText('添加');
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params : 'balanceList.id=' + id
				});
			}
		}
	});
	
	

	var  balanceForm = new Ext.form.FormPanel({
		id : 'balanceForm',
		title : '结算信息',
		frame : true,
		width : 330,
		region : 'east',
		autoScroll : true,
		labelAlign : 'right',
		labelWidth : 80,
		defaultType : 'textfield',
			defaults : {
			width : 200
		},
		items : [{  // Ext.form.Hidden
			id:'BalanceId',
			xtype : 'hidden',  // 隐藏的表单
			name : 'balanceList.id'
		},{
			id:'BalanceClient',
			fieldLabel : '客户',
			name : 'balanceList.client',
			allowBlank:false,
			blankText:'请输入客户名称'
		},{
			id:'BalancePayment',
			fieldLabel : '结算方式',
			allowBlank:false,
			blankText:'请输入结算方式',
			name : 'balanceList.payment'
		},{
			id:'BalanceContact',
			fieldLabel : '联系方式',
			allowBlank:false,
			blankText:'请输入联系方式',
			name : 'balanceList.contact'
		},{
			id: 'BalanceDate',
            xtype: 'datefield',
            fieldLabel: "装运时间",
            format : 'Y-m-d',
    		allowBlank:false,
            name: "balanceList.date"
		},{
			id:'BalanceDbv',
			fieldLabel : 'BV费(美)',
			name : 'balanceList.dbv',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入BV费'
		},{
			id:'BalanceRbv',
			fieldLabel : 'BV费(中)',
			name : 'balanceList.rbv',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入BV费'
		},{
			id:'BalanceBvRemark',
			fieldLabel : 'BV费备注',
			name : 'balanceList.bvRemark',
			allowBlank:false,
			blankText:'请输入BV费备注'
		},{
			id:'BalanceDcustoms',
			fieldLabel : '报关费(美)',
			name : 'balanceList.dcustoms',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入报关费'
		},{
			id:'BalanceRcustoms',
			fieldLabel : '报关费(中)',
			name : 'balanceList.rcustoms',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入报关费'
		},{
			id:'BalanceCustomRemark',
			fieldLabel : '报关费备注',
			name : 'balanceList.customRemark',
			allowBlank:false,
			blankText:'请输入BV费备注'
		},{
			id:'BalanceDport',
			fieldLabel : '码头费(美)',
			name : 'balanceList.dport',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入码头费'
		},{
			id:'BalanceRport',
			fieldLabel : '码头费(中)',
			name : 'balanceList.rport',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入码头费'
		},{
			id:'BalancePortRemark',
			fieldLabel : '码头费备注',
			name : 'balanceList.portRemark',
			allowBlank:false,
			blankText:'请输入码头费备注'
		},{
			id:'BalanceDsvc',
			fieldLabel : '服务费(美)',
			name : 'balanceList.dsvc',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入服务费'
		},{
			id:'BalanceRsvc',
			fieldLabel : '服务费(中)',
			name : 'balanceList.rsvc',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入服务费'
		},{
			id:'BalanceSvcRemark',
			fieldLabel : '服务费备注',
			name : 'balanceList.svcRemark',
			allowBlank:false,
			blankText:'请输入服务费备注'
		},{
			id:'BalanceDcard',
			fieldLabel : '单证费(美)',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			name : 'balanceList.dcard',
			allowBlank:false,
			blankText:'请输入单证费'
		},{
			id:'BalanceRcard',
			fieldLabel : '单证费(中)',
			name : 'balanceList.rcard',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入单证费'
		},{
			id:'BalanceCardRemark',
			fieldLabel : '单证费备注',
			name : 'balanceList.cardRemark',
			allowBlank:false,
			blankText:'请输入单证费备注'
		},{
			id:'BalanceDcnca',
			fieldLabel : 'CNCA(美)',
			name : 'balanceList.dcnca',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入CNCA'
		},{
			id:'BalanceRcnca',
			fieldLabel : 'CNCA(中)',
			name : 'balanceList.rcnca',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入CNCA'
		},{
			id:'BalanceCncaRemark',
			fieldLabel : 'CNCA备注',
			name : 'balanceList.cncaRemark',
			allowBlank:false,
			blankText:'请输入CNCA备注'
		},{
			id:'BalanceDocean',
			fieldLabel : '海运费(美)',
			name : 'balanceList.docean',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入海运费'
		},{
			id:'BalanceRocean',
			fieldLabel : '海运费(中)',
			name : 'balanceList.rocean',
			regex : /^\d+(\.\d+)?$/,
			regexText:'请输入有效的价格',
			allowBlank:false,
			blankText:'请输入海运费'
		},{
			id:'BalanceOceanRemark',
			fieldLabel : '海运费备注',
			name : 'balanceList.oceanRemark',
			allowBlank:false,
			blankText:'请输入海运备注'
		},{
			id:'BalanceSumRemark',
			fieldLabel : '合计备注',
			name : 'balanceList.sumRemark',
			allowBlank:false,
			blankText:'请输入合计备注'
		}],
		buttons : [button_add,button_clear,button_del]
	});
		return  balanceForm;
	}
  }
}();








